﻿using FMStudio.Documents.TemplateDocument.Data;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel.Composition;
using System.Xml.Serialization;

namespace FMStudio.Documents.TemplateDocument
{
    [Export(typeof(IDocument)), Export]
    public class ItemTemplateDocument : TemplateDocument
    {
        #region Fields
        private readonly ObservableCollection<Item> templateContent;
        #endregion

        public ItemTemplateDocument()
            : base(TemplateType.Item)
        {
            this.templateContent = new ObservableCollection<Item>();

            AddWeakEventListener(this.templateContent, TemplateContentCollectionChanged);
        }


        #region Properties
        [XmlArray(Order = 2)]
        [XmlArrayItem(Type = typeof(Folder)),
         XmlArrayItem(Type = typeof(ProjectItem))]
        public ObservableCollection<Item> TemplateContent { get { return this.templateContent; } }
        #endregion

        #region Methods
        #region Private Methods
        private void TemplateContentCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            this.IsModified = true;
        }
        #endregion
        #endregion
    }
}
